#ifndef _SCANNER_H_
#define _SCNANER_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <pthread.h>
#include <signal.h>
#include <iconv.h>
#include <time.h>
#include <sys/time.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "msgcmn.h"
#include "../logServer/clogger.h"
#include "../logServer/logger.h"

#define SCANNERLogDebug(fmt, args...) CLogger(MODULE_SCANNER, __FILE__, __LINE__, LOG_DEBUG, fmt, ##args);
#define SCANNERLogInfo(fmt, args...) CLogger(MODULE_SCANNER, __FILE__, __LINE__, LOG_INFO, fmt, ##args);
#define SCANNERLogNotice(fmt, args...) CLogger(MODULE_SCANNER, __FILE__, __LINE__, LOG_NOTICE, fmt, ##args);
#define SCANNERLogWarning(fmt, args...) CLogger(MODULE_SCANNER, __FILE__, __LINE__, LOG_WARNING, fmt, ##args);
#define SCANNERLogError(fmt, args...) CLogger(MODULE_SCANNER, __FILE__, __LINE__, LOG_ERR, fmt, ##args);
#define SCANNERLogCrit(fmt, args...) CLogger(MODULE_SCANNER, __FILE__, __LINE__, LOG_CRIT, fmt, ##args);
#define SCANNERLogAlert(fmt, args...) CLogger(MODULE_SCANNER, __FILE__, __LINE__, LOG_ALERT, fmt, ##args);
#define SCANNERLogEmerg(fmt, args...) CLogger(MODULE_SCANNER, __FILE__, __LINE__, LOG_EMERG, fmt, ##args);

typedef struct tag_LTE_CELL_INFO  
{
   uint8_t		    plmn[8];
   uint16_t         tac;
   uint16_t         pci;
   uint16_t         earfcn;
   int32_t          rsrq;
   int32_t          rsrp;
   int32_t          rssi;
   int32_t          priority;  
}LTE_CELL_INFO; 

typedef struct tag_LteSnifferResultTag
{
   U32		       cellNum;
   LTE_CELL_INFO   cell[64];
}LteSnifferResult;

typedef struct tag_WCDMA_CELL_INFO  
{
   uint8_t		    plmn[8];
   uint16_t         tac;
   uint16_t         psc;
   uint16_t         arfcn;
   int32_t          rscp;
}WCDMA_CELL_INFO; 

typedef struct tag_WcdmaSnifferResultTag
{
   U32		       cellNum;
   WCDMA_CELL_INFO   cell[64];
}WcdmaSnifferResult;

typedef struct tag_CMGRMI_MAIN_INFO
{
    uint32_t mode;
    uint32_t service_available;
    uint32_t valid;
    uint32_t idle;
    uint32_t ra_rnti;
    uint32_t c_rnti;
    uint32_t cqi_wb;
    uint32_t enb_num_tx_antenna;
} CMGRMI_MAIN_INFO;

typedef struct tag_CMGRMI_SERVING_CELL
{
    uint32_t earfcn;
    char mcc[8];
    char mnc[8];
    uint32_t tac;
    uint32_t num_mnc_digits;
    uint32_t serving_cell_id;
    int32_t freq_band_ind;
    int32_t dl_bandwidth;
    int32_t ul_bandwidth;
    int32_t serv_rssnr;
    int32_t cell_pci;
    int32_t cell_rsrq;
    int32_t cell_rsrp;
    int32_t cell_rssi;
    int32_t cell_idle_srxlev;
} CMGRMI_SERVING_CELL;

typedef struct tag_CMGRMI_LTE_INTRA
{
    uint32_t sib3_received;
    uint32_t earfcn;
    uint32_t serving_cell_id;
    uint32_t num_lte_cells;
} CMGRMI_LTE_INTRA;

typedef struct tag_CMGRMI_LTE_INTRA_CELL
{
    uint32_t cell_pci;
    int32_t cell_rsrq;
    int32_t cell_rsrp;
    int32_t cell_rssi;
    int32_t cell_idle_srxlev;
} CMGRMI_LTE_INTRA_CELL;

typedef struct tag_CMGRMI_LTE_FREQ
{
    uint32_t earfcn;
    uint32_t num_lte_cells;
    int32_t idle_threshX_low;
    int32_t idle_threshX_high;
    int32_t idle_cell_resel_priority;
} CMGRMI_LTE_FREQ;

typedef struct tag_CMGRMI_LTE_INTER
{
    uint32_t num_freqs;
    CMGRMI_LTE_FREQ Freq1;
    CMGRMI_LTE_FREQ Freq2;
} CMGRMI_LTE_INTER;

typedef struct tag_CMGRMI_LTE_INTER_CELL
{
    uint32_t cell_pci;
    uint32_t cell_rsrq;
    uint32_t cell_rsrp;
    int32_t cell_rssi;
    int32_t cell_idle_srxlev;
} CMGRMI_LTE_INTER_CELL;

typedef struct tag_CMGRMI_INFO
{
    CMGRMI_MAIN_INFO main_info;
    CMGRMI_SERVING_CELL serving_cell;
    CMGRMI_LTE_INTRA lte_intra;
    CMGRMI_LTE_INTRA_CELL lte_intra_cell[8];
    CMGRMI_LTE_INTER lte_inter;
    CMGRMI_LTE_INTER_CELL lte_inter_freq1_cell[8];
    CMGRMI_LTE_INTER_CELL lte_inter_freq2_cell[8];
} CMGRMI_INFO;

typedef struct tag_CNBP_INFO
{
    uint64_t mode;
    uint64_t lte_mode;
    uint64_t tds_mode;
} CNBP_INFO;

typedef struct tag_ACTIVE_SET
{
    int32_t cell_psc;
    int32_t cell_freq;
    int32_t cell_ssc;
    int32_t cell_sstd;
    float cell_totecio;
    float cell_ecio;
    int32_t cell_rscp;
    int32_t umts_sets_cell_tpc;
    int32_t umts_sets_cell_seccpichovsf;
    int32_t cell_winsize;
}ACTIVE_SET;

typedef struct tag_NEIGHBOR_SET
{
    int32_t cell_psc;
    int32_t cell_freq;
    int32_t cell_ssc;
    int32_t cell_sstd;
    float cell_totecio;
    float cell_ecio;
    int32_t cell_rscp;
    int32_t cell_winsize;
}NEIGHBOR_SET;

typedef struct tag_CRUS_INFO
{
    int32_t active_set_cells_num;
    ACTIVE_SET active_set[8];
    int32_t syncset_cells_nums;
    NEIGHBOR_SET sync_neighbor_set[32];
    int32_t asyncset_cells_nums;
    NEIGHBOR_SET async_neighbor_set[64];
}CRUS_INFO;

typedef struct tag_GSM_SERVING_CELL
{
    char mcc[8];
    char mnc[8];
    uint32_t bsic;
    int32_t rxqual;
    uint32_t lac;
    uint32_t id;
    uint32_t arfcn;
    int32_t pwr;
    int32_t c1;
    int32_t c2;
}GSM_SERVING_CELL;

typedef struct tag_GSM_NEIGHBOR_CELL
{
    uint32_t lac;
    uint32_t id;
    uint32_t arfcn;
    int32_t pwr;
    int32_t c1;
    int32_t c2;
}GSM_NEIGHBOR_CELL;

typedef struct tag_MONI_INFO
{
    GSM_SERVING_CELL serving_cell;
    int32_t neighbor_cells_num;
    GSM_NEIGHBOR_CELL neighbor_cell[6];
}MONI_INFO;

bool query_lte_cell_info(int32_t sms_serial_fd,CMGRMI_INFO *cmgrmi_info, uint64_t band);
bool query_wcdma_cell_info(int32_t sms_serial_fd,CRUS_INFO *crus_info);
bool query_gsm_cell_info(int32_t sms_serial_fd,MONI_INFO *moni_info);

#endif
